{extend name="base" /} {block name="body"}
<div class="admin-main">
    <div class="layui-field-box layui-form">
        <a data-url="{:url('admin/articleCategory/save')}" class="layui-btn layui-btn-sm" id="addSiteCate">
            <i class="layui-icon">&#xe608;</i> 添加分类
        </a>

        <table class="layui-table admin-table">
            <thead>
            <tr>
                <th width="5%" style="text-align: center">ID</th>
                <th width="20%" style="text-align: center">分类名称</th>
<!--                <th width="20%" style="text-align: center">接受LaySNS官方数据</th>-->
                <th width="10%" style="text-align: center">资源数量</th>
                <th width="15%" style="text-align: center">基本操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="category_level_list" id="vo"}
            <tr>
                <td align="center">{$vo.id}</td>
                <td align="center">{neq name="vo.level" value="1"}|{php}for($i=1;$i
                    <$vo[ 'level'];$i++){echo ' --';}{/php}{/neq} {$vo.name}
                </td>

<!--                <td align="center">-->
<!--                    <input type="checkbox" name="accept_ls_push" lay-skin="switch" lay-text="接收|屏蔽" lay-filter="switchpush" value="{$vo['accept_ls_push']}" {php}echo $vo[ 'accept_ls_push']==1 ? 'checked' : '';{/php}>-->
<!--                </td>-->

                <td align="center">
                    0
                </td>
                <td align="center">
                    <a class="layui-btn layui-btn-normal layui-btn-sm cate-edit" data-id="{$vo.id}" data-name="{$vo.name}"
                       href="javascript:;">修改</a>
                    <a href="javascript:;" data-id="{$vo.id}"
                       data-url="{:url('admin/articleCategory/delete',array('id'=>$vo['id']))}" data-opt="del"
                       class="elementdel layui-btn layui-btn-danger layui-btn-sm ajax-delete">删除</a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </div>


</div>
{/block} {block name="js"}
<script type="text/javascript" src="__ADMIN__/js/delelement.js"></script>
{/block} {block name="script"}
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            jq = layui.jquery;


        var accept_ls_push = 0;
        form.on('switch(switchpush)', function (data) {
            loading = layer.load(2, {
                shade: [0.2, '#000']
            });
            if (data.elem.checked) {
                status = 1;
            } else {
                status = 0;
            }
            var url = "{:url('admin/articleCategory/toggle')}?id=" + data.value + '&status=' + status + '&name=accept_ls_push';
            jq.get(url, function (data) {

                if (data.code == 200) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            });
            return false;
        });
        jq('#addSiteCate').on('click', function (data) {
           var url=jq(this).data('url');

            layer.prompt({title: '新增分类'}, function(text, index){
                jq.post(url, {name:text},function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        },function () {
                            location.reload();
                        });
                    }else {
                        layer.msg(res.msg, {
                            icon: 2,
                            anim: 6,
                            time: 1000
                        });
                    }
                });
            });

        });
        jq('.cate-edit').on('click', function (data) {

            var id=jq(this).data('id');
            var name=jq(this).data('name');
            var url = "{:url('admin/articleCategory/update')}?id=" + id;
            layer.prompt({title: '修改分类名',value:name}, function(text, index){
                jq.post(url, {name:text},function (res) {

                if (res.code == 200) {

                    layer.msg(res.msg, {
                        icon: 1,
                        time: 1000
                    },function () {
                        location.reload();
                    });
                } else {

                    layer.msg(res.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
             });
            });
            return false;
        });
    })
</script>
{/block}